<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>es6默认值参数和可变参数</title>
</head>
<body>
    <script>

    //默认值参数
    function add(a=1,b=2){
        return a+b;
    }
    //此时如果不传递参数，就会取默认值参数
    console.log(add());
      //可变参数es5和es6可变参数的区别
      let book = {
        title:'java入门到精通',
        author:'小马哥',
        price:19.8
      }

      let bookData = pickEs5(book,'author','price')
      let bookData1 = pickEs6(book,'author','price')

      function pickEs5(Obj){
        //es5的写法,所有参数都会被封装在arguments中
        console.log(arguments)
        let filterData = Object.create(null)
        for(i = 1;i<arguments.length;i++){
          filterData[arguments[i]] = Obj[arguments[i]]
        }
        return filterData;
      }
      console.log(bookData)
        function pickEs6(Obj,...args){
        console.log(args)
        //es6的写法,所有参数都会被封装args中,args是一个数组
        console.log(arguments)
        let filterData = Object.create(null)
        for(i = 0;i<args.length;i++){
          filterData[args[i]] = Obj[args[i]]
        }
        return filterData;
      }
      console.log(bookData1)


    </script> 
</body>
</html>